#include "stdafx.h"
#include "God.h"


CGod::CGod()
{
	CWorld m_World;
}

CGod::~CGod() {}

bool CGod::Execute(string expression)
{
	if (expression.empty())
		return true;
	try
	{
		vector<string> commands = this->ScanSequence(expression);
	}
	catch(invalid_argument const& e)
	{
		throw;
	}
	return true;
	//return false;
}

vector<string> CGod::ScanSequence(string expression)
{
	vector<string> commands;
	string expr = Trim(expression);
	size_t pos_separator = expr.find(separator);
	if (pos_separator == string::npos)
	{
		stringstream ss;
			ss << "Warning: missing " << separator;
		throw std::invalid_argument(ss.str());
	}
	else
	{
		while (pos_separator != string::npos)
		{
			string command = expr.substr(0 , pos_separator);
			commands.push_back(command);
			expr = expr.substr(pos_separator + separator.size());
			pos_separator = expr.find(separator);
		}
		if (!expr.empty())
		{
			stringstream ss;
			ss << "Warning: missing " << separator << " behand " << "'" << expr << "'";
			throw std::invalid_argument(ss.str());
		}
	}
	return commands;
}


